<template>
  <div>
    <bread-crumb :crumb="crumb"></bread-crumb>
    <el-row>
      <el-col :span="8">
        <el-input placeholder="请输入用户名搜索" class="input-with-select">
          <el-button slot="append" icon="el-icon-search"></el-button>
        </el-input>
      </el-col>
    </el-row>
    <el-card>
      <el-table :data="accountList" border stripe>
        <el-table-column type="index" label="#"></el-table-column>
        <el-table-column label="用户名" prop="username"></el-table-column>
        <el-table-column label="注册时间" prop="registerTime"></el-table-column>
        <el-table-column label="权限">
          <template slot-scope="scope">
            <el-tag>{{scope.row.authName}}</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="联系电话" prop="mobile"></el-table-column>
        <el-table-column label="不否禁用账号">
          <template slot-scope="scope">
            <el-switch
              v-model="scope.row.disabled"
              active-text="禁用账号"
              inactive-text="启用账号"
              active-color="#ff4949"
              inactive-color="#13ce66"
            >
            </el-switch>
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button size="mini" type="primary" icon="el-icon-edit" @click="editUser(scope.row.id)">修改</el-button>
            <el-button size="mini" type="danger" icon="el-icon-edit" @click="deleteAccount(scope.row.id)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
    <!-- 分页 -->
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="queryInfo.pagenum"
      :page-sizes="[100, 200, 300, 400]"
      :page-size="100"
      layout="total, sizes, prev, pager, next, jumper"
      :total="400">
    </el-pagination>
    <!-- 修改用户信息对话框 -->
    <el-dialog
      title="提示"
      :visible.sync="editUserDialogVisible"
      width="50%"
    >
      <el-form ref="form" label-width="80px">
        <el-form-item label="用户名: ">
          <el-input disabled value="123123"></el-input>
        </el-form-item>
        <el-form-item label="权限">
          <el-select v-model="value" placeholder="请选择">
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
              :disabled="item.disabled"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="联系电话: ">
          <el-input value="13812345678"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer">
        <el-button @click="editUserDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="editUserDialogVisible = false">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import breadCrumb from '../../components/common/Breadcrumb'
export default {
  name: 'accountlist',
  components: {
    breadCrumb
  },
  data () {
    return {
      accountList: [],
      editUserDialogVisible: false,
      options: [
        {
          value: 0,
          label: '上帝',
          disabled: true
        },
        {
          value: 1,
          label: '业务经理'
        },
        {
          value: 2,
          label: '业务主管'
        },
        {
          value: 3,
          label: '普通业务员'
        }
      ],
      value: '',
      // 分页查询数据
      queryInfo: {
        pagenum: 1,
        pagesize: 5
      },
      crumb: ['账户管理', '账户列表']
    }
  },
  created () {
    this.getAccountList()
  },
  methods: {
    async getAccountList () {
      const { data: res } = await this.$axios.get('accountlist.json')
      if (res.meta.status !== 200) {
        return this.$message.error('获取账户列表失败')
      }
      this.accountList = res.data
    },
    editUser (id) {
      this.editUserDialogVisible = true
      console.log(id)
    },
    async deleteAccount (id) {
      console.log(id)
      const result = await this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).catch(err => err)
      if (result === 'confirm') {
        return this.$message.success('删除成功')
      }
      return this.$message.info('已中止删除操作')
    },
    handleSizeChange () {},
    handleCurrentChange () {}
  }
}
</script>
<style lang="scss" scoped>
.el-card {
  margin-top: 15px;
}
</style>
